class Solution {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int sum=0;
        for(int i=nums.length-1;i>=2;i--){
            int right=i-1,left=0;
            while(right>left){
                if(nums[left]+nums[right]>nums[i]){
                    sum=sum+right-left;
                    right--;
                }
                else{
                    left++;
                }
            }
        }
        return sum;
    }
}